﻿using com.yoozoo.gta.Gameplay.RTS;
using TMPro;
using UnityEngine;
using Yoozoo.UI.YGUI;

namespace Yoozoo.Gameplay.RTS
{
    public class CargoTruckHudLod0 : MonoBehaviour
    {
        public YImage AllianceIconBg;
        public YImage AllianceIcon;
        public TextMeshPro AllianceName;
        public GameObject StateObj;
        public TextMeshPro StateDescText;
        public GameObject TroopCountObj;
        public TextMeshPro TroopCountText;

        private bool isRefreshShowSuccess;

        public void RefreshShow(RtsServerInfo serverInfo)
        {
            if (isRefreshShowSuccess) return;
            if (AllianceIconBg && !string.IsNullOrEmpty(serverInfo.LogoBg))
            {
                isRefreshShowSuccess = true;
                ArmyManager.Instance.ResourceManager.SetAllianceIcon(serverInfo.LogoBg, AllianceIconBg);
                ColorUtility.TryParseHtmlString(serverInfo.LogoBgColor, out Color color);
                AllianceIconBg.color = color;
            }
            if (AllianceIcon && !string.IsNullOrEmpty(serverInfo.Logo))
            {
                isRefreshShowSuccess = true;
                ArmyManager.Instance.ResourceManager.SetAllianceIcon(serverInfo.Logo, AllianceIcon);
                ColorUtility.TryParseHtmlString(serverInfo.LogoColor, out Color color);
                AllianceIcon.color = color;
            }
            if (AllianceName && !string.IsNullOrEmpty(serverInfo.name))
            {
                isRefreshShowSuccess = true;
                AllianceName.text = serverInfo.name;
            }
        }

        public void RefreshDescText(bool bIsActiveDescText, string content)
        {
            StateObj.SetActive(bIsActiveDescText);
            if (bIsActiveDescText)
            {
                StateDescText.text = content;
            }
        }

        public void SetTroopCount(int troopCount)
        {
            TroopCountObj.SetActive(troopCount != 0);
            TroopCountText.text = "x" + troopCount.ToString();
        }
    }
}
